package com.chenjiaru.kafka.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TestConsumer {

    /**
     * kafka监听器
     * @param record    消息对象
     * @param ack       {@link Acknowledgment}
     */
    @KafkaListener(topics = "${spring.kafka.topic.t1}", groupId = "test4")
    public void listenZhugeGroup(ConsumerRecord<String, String> record, Acknowledgment ack) {
        String value = record.value();
        log.info("消费者1，消费一条消息-{}", value);
        //手动提交offset
        ack.acknowledge();
    }

    /**
     * kafka监听器
     * @param record    消息对象
     * @param ack       {@link Acknowledgment}
     */
    @KafkaListener(topics = "${spring.kafka.topic.t1}",groupId = "test4")
    public void listenTulingGroup(ConsumerRecord<String, String> record, Acknowledgment ack) {
        String value = record.value();
        log.info("消费者2，消费一条消息-{}", value);
        //手动提交offset
        ack.acknowledge();
    }
}
